// 既要校验是否是github仓库和gitee仓库, 的合法url
export const validateRepositoryUrl = async (_rule: never, value: string) => {
  const regex =
    /^https?:\/\/(www\.)?(github\.com|gitee\.com)\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(\.git)?$/
  if (value && !regex.test(value)) {
    return Promise.reject('Please enter a valid Repository URL!')
  } else {
    return Promise.resolve()
  }
}

export const validateUrl = async (_rule, value) => {
  if (!value) {
    return Promise.reject(new Error('URL地址不能为空!'))
  } else {
    if (
      !/^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/.test(
        value
      )
    ) {
      return Promise.reject(new Error('请输入正确的URL地址!'))
    } else {
      return Promise.resolve()
    }
  }
}
